package com.demo;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class PasswordEncoderExample {
    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

        String password = "123456";

        // 加密
        String encodedPassword = encoder.encode(password);
        System.out.println("Encoded password: " + encodedPassword);

        // 验证
        boolean isMatch = encoder.matches(password, encodedPassword);
        System.out.println("Password matches: " + isMatch);

        // 错误的密码验证
        boolean isWrongMatch = encoder.matches("wrongPassword", encodedPassword);
        System.out.println("Wrong password matches: " + isWrongMatch);
    }
}
